package com.info.zhiduoduo.repository.mapper.company;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.company.CompanyTransferMakerGrouponDto;
import com.info.zhiduoduo.repository.entity.company.CompanyTransferMakerGroupon;

import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2021-08-21
 */
public interface CompanyTransferMakerGrouponMapper extends BaseMapper<CompanyTransferMakerGroupon> {

	@Select("<script>" +
			" select ctmg.*,c.compname," +
			" topay.pay_id as toPayId,topay.balance as toBalance,topayment.pay_name as toPayName,topayment.pay_name_alias as toPayNameAlias, " +
			" frompay.pay_id as fromPayId,frompay.balance as fromBalance,frompayment.pay_name as fromPayName,frompayment.pay_name_alias as fromPayNameAlias " +
			" from zdd_company_transfer_maker_groupon ctmg " +
			" join zdd_company c on c.compid = ctmg.compid " +
			" left join zdd_company_payment topay on topay.id = ctmg.to_comp_pay_id " +
			" left join zdd_company_payment frompay on frompay.id = ctmg.from_comp_pay_id " +
			" left join zdd_payment topayment on topayment.id = topay.pay_id " +
			" left join zdd_payment frompayment on frompayment.id = frompay.pay_id " +
			" where c.compname like '%${name}%' " +
			" and if(#{state}=0, 1=1, ctmg.state = #{state}) " +
			" <if test='from != null'> " +
			"  and ctmg.apply_time &gt;= #{from} " +
			" </if> " +
			" <if test='to != null'> " +
			"  and ctmg.apply_time &lt;= #{to} " +
			" </if> " +
			" order by ctmg.id desc " +
			"</script>")
	List<CompanyTransferMakerGrouponDto> list(String name, int state, Date from, Date to);
}
